<!DOCTYPE html>
<html class="no-js" lang="zh_CN">

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1, maximum-scale=1">

    <title>${system_admin_title}</title>
    #required_css
</head>

<body>#loading


<div class="app $!layout">
    <!-- 头部菜单 -->
    #header
    <section class="layout">
        <!-- 菜单 -->
        #sidebar
        <!-- 内容主体 -->
        <section class="container">
            <section class="main-content">
                <!-- 主体操作栏 -->
                <header class="header navbar">
                    <!-- 左按钮区 -->
                    <div class="btn-group tool-button">
                        <a class="btn btn-primary navbar-btn" href="$!basePath/system/unit"><i class="ti-angle-left"></i> 返回</a>
                    </div>
                </header>
                <div class="content-wrap">
                    <div class="wrapper">
                        <section class="panel pt20 pl20 pr20">
                            <form id="unitAddForm" role="form" class="form-horizontal parsley-form" data-parsley-validate action="$!basePath/system/unit/add/do" method="post">
                                <div class="row mb10">
                                    <div class="col-lg-12 col-md-12">
                                        <div class="form-group has-feedback">
                                            <label for="parentId" class="col-sm-1 control-label">上级组织</label>
                                            <div class="col-sm-10">
                                                <div class="input-group">
                                                    #if($!isSystemUnit == true)
                                                    <input id="parentId" type="text" class="form-control" placeholder="不选择默认为顶级组织" disabled value="$!parentUnit.name"/>
                                                    #else
                                                    <input id="parentId" type="text" class="form-control" placeholder="必须选择一个上级组织" disabled value="$!parentUnit.name"/>
                                                    #end
                                                    <span class="input-group-btn">
                                                        <button type="button" class="btn btn-primary" onclick="doSelectParentUnit()" #if($!noUnit) disabled="disabled" #end><i class="ti-plus"></i> 选择</button>
                                                    </span>
                                                </div>
                                                <input type="hidden" name="parentId" value="$!parentUnit.id">
                                            </div>
                                        </div>
                                        <div class="hr-line-dashed"></div>
                                        <div class="form-group">
                                            <label for="name" class="col-sm-1 control-label">名称<span class="text-danger">*</span></label>
                                            <div class="col-sm-10">
                                                <input type="text" class="form-control" name="name" data-parsley-required="true" placeholder="#springMessage('system.sys.unit.name')">
                                            </div>
                                        </div>
                                        <div class="hr-line-dashed"></div>
                                        <div class="form-group">
                                            <label for="address" class="col-sm-1 control-label">#springMessage('system.sys.unit.addr')</label>
                                            <div class="col-sm-10">
                                                <input type="text" name="address" class="form-control" placeholder="组织所在地址">
                                                <p class="help-block no-m">例如：安徽省合肥市高新区长江西路001号</p>
                                            </div>
                                        </div>
                                        <div class="hr-line-dashed"></div>
                                        <div class="form-group">
                                            <label for="contact" class="col-sm-1 control-label">#springMessage('system.sys.unit.contact')</label>
                                            <div class="col-sm-4">
                                                <input type="text" name="contact" class="form-control" placeholder="联系人姓名">
                                            </div>
                                            <label for="mobile" class="col-sm-1 control-label">#springMessage('system.sys.unit.phone')</label>
                                            <div class="col-sm-5">
                                                <input type="text" name="mobile" class="form-control" placeholder="固定电话、手机号码等">
                                            </div>
                                        </div>
                                        <div class="hr-line-dashed"></div>
                                        <div class="form-group">
                                            <label for="email" class="col-sm-1 control-label">电子邮件</label>
                                            <div class="col-sm-4">
                                                <input type="text" name="email" class="form-control" placeholder="格式：xxx@xxx.xx" data-parsley-type="email" data-parsley-trigger="change">
                                            </div>
                                            <label for="web" class="col-sm-1 control-label">网站地址</label>
                                            <div class="col-sm-5">
                                                <input type="text" name="web" class="form-control" placeholder="http://">
                                            </div>
                                        </div>
                                        <div class="hr-line-dashed"></div>
                                        <div class="form-group">
                                            <label for="enabled" class="col-sm-1 control-label">是否启用</label>
                                            <div class="col-sm-4 switcha">
                                                <div class="mr15">
                                                    <input type="checkbox" name="enabled" class="js-switch-blue" checked="checked">
                                                </div>
                                            </div>
                                            #if($!isSystemUnit == true)
                                            <label for="enabled" class="col-sm-1 control-label">系统组织</label>
                                            <div class="col-sm-4 switcha">
                                                <div class="mr15">
                                                    <input id="system_unit" type="checkbox" name="system" class="js-switch-blue">
                                                </div>
                                            </div>
                                            #end
                                        </div>
                                    </div>
                                    <div class="col-lg-12 col-md-12 col-sm-12">
                                        <div class="hr-line-dashed"></div>
                                        <div class="form-group text-center">
                                            <div>
                                                <button class="btn btn-primary btn-form-submit btn-parsley" data-loading-text="正在提交...">立即提交</button>
                                                <button type="reset" class="btn btn-default btn-outline">重置</button>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </form>
                        </section>
                    </div>
                </div>
                <a class="exit-offscreen"></a>
            </section>
        </section>
    </section>
</div>
#required_js

<script type="text/javascript">
    ns.requireJS(["/framework/plugins/switchery/switchery.js",
        "/framework/js/form/form.js",
        "/framework/js/view/toast.js",
        "/framework/js/view/tree.js",
        "/framework/js/form/validator.js",
        "/framework/js/common/unit.js"
    ]);
    function doSelectParentUnit(){
        ns.common.unit.select({
            showTopUnit : true,
            callback : function(units){
                var unit = units[0];
                $("#unitAddForm #parentId").val(unit.name);
                $("#unitAddForm input[name='parentId']").val(unit.id);
            }
        })
    }
    ns.ready(function () {
        $('#unitAddForm').ajaxForm({
            beforeSubmit: function (arr, $form, options) {
                $form.find("button:submit").button("loading");
            },
            success: function (data, statusText, xhr, $form) {
                if (data.success == true) {
                    if ($form.find("#system_unit").is(":checked")) {
                        Toast.success("组织增加成功！");
                        var parentName = $("#unitAddForm #parentId").val();
                        $form.resetForm();
                        $("#unitAddForm #parentId").val(parentName);
                    } else {
                        ns.tip.confirm("<h5>组织增加成功！</h5>目前此组织不包含任何菜单功能，是否立即配置组织拥有的菜单？", function () {
                            window.location.href = "$!basePath/system/unit/res/" + data.id;
                        }, function () {
                            var parentName = $("#unitAddForm #parentId").val();
                            $form.resetForm();
                            $("#unitAddForm #parentId").val(parentName);
                        });
                    }
                } else {
                    Toast.error(data.message);
                }
                $form.find("button:submit").button("reset");
            }
        });
    });

</script>
#loading_close
</body>
</html>
